package o;

import android.content.Context;
import android.os.Build.VERSION;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import androidx.annotation.NonNull;

public class dfi {
    private static WindowManager ˎ(@NonNull Context context) {
        return (WindowManager) context.getApplicationContext().getSystemService("window");
    }

    public static boolean ˋ(@NonNull Context context, @NonNull View view, @NonNull LayoutParams layoutParams) {
        if (context == null || view == null || layoutParams == null) {
            Log.e("FloatWindowManager", "the param is null, add view failed");
            return false;
        }
        try {
            ˎ(context).addView(view, ˎ(layoutParams));
            return true;
        } catch (Throwable e) {
            Log.e("FloatWindowManager", "addView exception", e);
            return false;
        }
    }

    public static void ˊ(@NonNull Context context, @NonNull View view) {
        if (context == null || view == null) {
            Log.e("FloatWindowManager", "the param is null, remove view failed");
            return;
        }
        try {
            ˎ(context).removeView(view);
        } catch (Throwable e) {
            Log.e("FloatWindowManager", "removeView exception", e);
        }
    }

    public static boolean ˎ(@NonNull Context context, @NonNull View view, @NonNull LayoutParams layoutParams) {
        if (context == null || view == null || layoutParams == null) {
            Log.e("FloatWindowManager", "the param is null, update view failed");
            return false;
        }
        try {
            ˎ(context).updateViewLayout(view, ˎ(layoutParams));
            return true;
        } catch (Throwable e) {
            Log.e("FloatWindowManager", "updateView exception", e);
            return false;
        }
    }

    private static LayoutParams ˎ(@NonNull LayoutParams layoutParams) {
        if (VERSION.SDK_INT >= 26) {
            layoutParams.type = 2038;
        }
        if (VERSION.SDK_INT <= 18 || VERSION.SDK_INT == 25) {
            layoutParams.type = 2002;
        }
        layoutParams.setTitle("com.huawei.hms.game.buoy");
        return layoutParams;
    }
}
